package com.google.code.tretris.rendering;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

public final class BufferUtil {
	public static FloatBuffer wrap(float[] array) {
		ByteBuffer cbb = ByteBuffer.allocateDirect(array.length * 4);
		cbb.order(ByteOrder.nativeOrder());
		FloatBuffer buffer = cbb.asFloatBuffer();
		buffer.put(array);
		buffer.position(0);
		return buffer;
	}

	public static ByteBuffer wrap(byte[] array) {
		ByteBuffer cbb = ByteBuffer.allocateDirect(array.length);
		cbb.order(ByteOrder.nativeOrder());
		cbb.put(array);
		return cbb;
	}

	public static ShortBuffer wrap(short[] array) {
		ByteBuffer ibb = ByteBuffer.allocateDirect(array.length * 2);
		ibb.order(ByteOrder.nativeOrder());
		ShortBuffer buffer = ibb.asShortBuffer();
		buffer.put(array);
		buffer.position(0);
		return buffer;
	}
}
